<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<style>
		.yanshi {
			height: 38px;
		    line-height: 1.3;
		    line-height: 38px\9;
		    border: 1px solid #e6e6e6;
		    background-color: #fff;
		    border-radius: 2px;
		    width: 211px;
		}
	</style>
<body style="padding:10px;">
  <div class="tplay-body-div">
    <div class="layui-tab">
      <ul class="layui-tab-title">
        <li><a href="{:url('admin/house/house_list')}" class="a_menu">房间管理</a></li>
        <li class="layui-this"><a href="#">新增房间</a></li>
      </ul>
    </div> 
    <div style="margin-top: 20px;">
    </div>
    <form class="layui-form" id="admin">

      <div class="layui-form-item">
        <label class="layui-form-label">所属门店</label>
        <div class="layui-input-inline">
          <select onchange="select_trade(this);" lay-ignore class="yanshi" name="store_id" lay-filter="aihao"  lay-verify="required" lay-search>
            <option value="">请选择门店</option>
            {volist name="info['hyjt_store']" id="vo"}
            <option value="{$vo.id}" {notempty name="$info.house.store_id"}{eq name="$info.house.store_id" value="$vo.id"} selected=""{/eq}{/notempty}>{$vo.store_name}</option>
            {/volist}
          </select>
        </div>
        <label class="layui-form-label"><a href="{:url('admin/store/addstore')}">新建门店</a></label>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">房型分类</label>
        <div class="layui-input-inline">
          <select id="room_id" lay-ignore class="yanshi" name="room_id" lay-filter="aihao"  lay-verify="required" lay-search>
            {empty name="id"}
						<option value="">请选择房型分类</option>
						{else /}
						{volist name="info['room']" id="vo"}
						<option value="{$vo.id}" {if condition="$info.house.room_id eq $vo.id"}selected{/if}>{$vo.room_name}</option>
						{/volist}
						{/empty} 
          </select>
        </div>
        <label class="layui-form-label"><a href='/admin/house/add_room'>新建分类</a></label>
      </div>
      
     <div class="layui-form-item">
        <label class="layui-form-label">房间名称</label>
        <div class="layui-input-inline">
          <input name="h_name" lay-verify="required" placeholder="请输入房间名称" autocomplete="off" class="layui-input" type="text" {notempty name="$info.house.h_name"}value="{$info.house.h_name}"{/notempty}>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">房间编号</label>
        <div class="layui-input-inline">
          <input name="num_id" lay-verify="required" placeholder="请输入房间编号" autocomplete="off" class="layui-input" type="text" {notempty name="$info.house.num_id"}value="{$info.house.num_id}"{/notempty}>
        </div>
      </div>
      
      <!--<div class="layui-form-item">
        <label class="layui-form-label">售价</label>
        <div class="layui-input-inline">
          <input name="h_price" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.house.h_price"}value="{$info.house.h_price}"{/notempty}>
        </div>
      </div>-->
      
      {notempty name="$info.house"}
      <input type="hidden" name="id" value="{$info.house.id}">
      {/notempty}
      
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
      
    </form>


    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <script>
        var message;
        layui.config({
            base: '__JS__/',
            version: '1.0.1'
        }).use(['app', 'message'], function() {
            var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
            //将message设置为全局以便子页面调用
            message = layui.message;
            //主入口
            app.set({
                type: 'iframe'
            }).init();
        });
        
        
      layui.use(['layer', 'form'], function() {
          var layer = layui.layer,
              $ = layui.jquery,
              form = layui.form;
          $(window).on('load', function() {
              form.on('submit(admin)', function(data) {
                  $.ajax({
                      url:"{:url('admin/house/add_house')}",
                      data:$('#admin').serialize(),
                      type:'post',
                      async: false,
                      success:function(res) {
                          if(res.code == 1) {
                              layer.alert(res.msg, function(index){
                                location.href = res.url;
                              })
                          } else {
                              layer.msg(res.msg);
                          }
                      }
                  })
                  return false;
              });
          });
      });
      
      function select_trade(obj){
				var store_id=$(obj).val();
				var lay = layer.load(0, {shade: false,time: 1000});
				$.ajax({
						type: 'post',
						url: "{:url('house/get_store')}",
						data: {
							store_id:store_id
						},
						success: function(data) {
							var list=data.data;
							if(list != ''){ 
								var html="";
								for(var i=0;i<list.length;i++){
									var trade=list[i];  
									html+="<option value="+trade['id']+" >"+trade['room_name']+"</option>"; 
								}
							}else{ 
								html = "<option value='0'>请选择房型分类</option>";
							}
							$("#room_id").html(html);
						}
				})
				
			}
    </script>
  </div>
</body>
</html>